// import React, { useState, useReducer } from "react";
import React, { useReducer } from "react";

// 标准的--纯函数--
const reducer = (state, action) => {
  if (action === "+") {
    return state + 1;
  } else if (action === "-") {
    return state - 1;
  }
};

function Reducer() {
  // const [count, setCount] = useState(1);

  const [count, dispatch] = useReducer(reducer, 1);

  return (
    <>
      <button onClick={() => dispatch("-")}>-</button>
      {/* <button onClick={() => setCount(count - 1)}>-</button> */}
      <span>Count：{count}</span>
      {/* <button onClick={() => setCount(count + 1)}>+</button> */}
      <button onClick={() => dispatch('+')}>+</button>
    </>
  );
}

export default Reducer;